package book.ioperations;

import book.Book;
import book.BookList;

import java.util.Scanner;

public class BorrowOperations implements IOperations{
    public void work(BookList bookList){
        System.out.println("借阅图书...");

        Scanner scanner = new Scanner(System.in);
        System.out.println("请输入要借阅的图书名：");
        String name = scanner.nextLine();

        int currentsize = bookList.getUsedSize();

        for (int i = 0; i < currentsize; i++) {
            Book book = bookList.getBook(i);
            if(book.getName().equals(name)){
                if(book.isBorrowed()){
                    System.out.println("该书已被借阅...");
                    book.setBorrowed(false);
                    return;
                }else{
                    System.out.println("借阅成功！");
                    return;
                }
            }
        }
        System.out.println("未找到此书，借阅失败！");
    }
}
